<?php
	$ls_gridname	= 'dtl_penghargaan';


// ----------------- >> Form Detail << ----------------- ?>
<script type="text/javascript">
	var controllerPenghargaan = 'hrd_detail_penghargaan';
    var idKaryawan = $('#id_karyawan_pk').val();

	$(document).ready(function(){
		// Setup Form
		$('#form_<?php echo $ls_gridname; ?>').setupForm([
			{ name: 'id_detail_penghargaan_pk', type:'text', size:'medium' },
			{ name: 'no_sk_penghargaan', type:'text', size:'medium', noempty:true },
			{ name: 'id_penghargaan_fk', size: 'medium', data:<?php echo json_encode($listPenghargaan); ?> },
			{ name: 'tgl_penghargaan', type: 'date' },
			{ name: 'pemberi_penghargaan', type: 'text', size:'long' },
			{ name: 'ket_penghargaan', type: 'text', size:'long' }
		], {}, { prefix:'<?php echo $ls_gridname; ?>_' });
		
		// Set Hidden Object
		$('#<?php echo $ls_gridname; ?>_id_detail_penghargaan_pk').hide();
		
		// Create Dialog
		$('#form_<?php echo $ls_gridname; ?>_container').dialog({
			closed:true,
			modal:true,
			title: '_',
			width:550,
			height: 300,
			buttons:[{
				text:'Save',
				iconCls:'icon-save',
				handler:function(){
					$('#form_<?php echo $ls_gridname; ?>').submitForm('/'+controllerPenghargaan+'/ajax_post/'+idKaryawan, { onComplete : function(){ $('#form_<?php echo $ls_gridname; ?>_container').dialog('close'); 
						$('#<?php echo $ls_gridname; ?>').datagrid('reload'); }} );
				}
			},{
				text:'Close',
				iconCls:'icon-cancel',
				handler:function(){
					$('#form_<?php echo $ls_gridname; ?>_container').dialog('close');
				}
			}]
		});

	});
</script>
<div id="form_<?php echo $ls_gridname; ?>_container" style="padding:5px;width:600px;height:400px;">
	<div id="form_<?php echo $ls_gridname; ?>">
    <table class="tb_form" style="width:100%;" cellpadding="0" cellspacing="0">
    <tr>
        <td class="label">No SK Penghargaan</td>
        <td><input id="no_sk_penghargaan" /><input id="id_detail_penghargaan_pk" /></td>
    </tr>
    <tr>
        <td class="label">Penghargaan</td>
        <td><input id="id_penghargaan_fk" /></td>
    </tr>
    <tr>
        <td class="label">Tgl Penghargaan</td>
        <td><input id="tgl_penghargaan" /></td>
    </tr>
    <tr>
        <td class="label">Pemberi Penghargaan</td>
        <td><input id="pemberi_penghargaan" /></td>
    </tr>
    <tr>
        <td class="label">Keterangan</td>
        <td><input id="ket_penghargaan" /></td>
    </tr>
    </table>
	</div>
</div>
<?php 



// ----------------- >> Table Detail << ----------------- ?>
<script type="text/javascript">
	$(document).ready(function(){
		$('#<?php echo $ls_gridname; ?>').datagrid({
			url:gs_path+'/'+controllerPenghargaan+'/getdata/'+idKaryawan,
			<?php if($mode!='view'){ 
			// -->> Toolbar [Start]
			// Only Appear On Mode Create / Edit ?>
			toolbar:[{
				text:'Tambah',
				iconCls:'icon-add',
				handler:function(){
					resetError();
					$('#<?php echo $ls_gridname; ?>_id_detail_penghargaan_pk').readonly();
					$('#form_<?php echo $ls_gridname; ?>_container').dialog('open');
					$('#form_<?php echo $ls_gridname; ?>').data('mode', 'create');
					$('#form_<?php echo $ls_gridname; ?>_container').prev().find('.panel-title').html('Tambah Data');
					
					$('#form_<?php echo $ls_gridname; ?>').resetForm();
					$('#form_<?php echo $ls_gridname; ?>').focusFirst();
				}
			},'-',{
				text:'Ubah',
				iconCls:'icon-edit',
				handler:function(){
					var oSel=$('#<?php echo $ls_gridname; ?>').datagrid('getSelected'); 
					if(oSel==null){ alert('Please select row!'); }
					else{ 
						resetError();
						$('#<?php echo $ls_gridname; ?>_id_detail_penghargaan_pk').readonly();
						$('#form_<?php echo $ls_gridname; ?>_container').dialog('open');
						$('#form_<?php echo $ls_gridname; ?>').data('mode', 'edit');
						$('#form_<?php echo $ls_gridname; ?>_container').prev().find('.panel-title').html('Ubah Data');
						
						jsonToForm(oSel, {prefix:'<?php echo $ls_gridname; ?>_'});
						$('#form_<?php echo $ls_gridname; ?>').focusFirst();
					}
				}
			},'-',{
				text:'Hapus',
				iconCls:'icon-remove',
				handler:function() {
					var oSel = $('#<?php echo $ls_gridname; ?>').datagrid('getSelected'); 
                    if (oSel == null) { 
                        $.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
                    } else { 
                        var url = gs_path+'/'+controllerPenghargaan+'/ajax_delete?id_detail_penghargaan_pk='+oSel.id_detail_penghargaan_pk;
                        // Confirm Hapus
						$.messager.confirm('Confirm', 'yakin menghapus data ini?', function(r){
			                if (r){
			                    $.get( url, function(  ) {
								  	$('#<?php echo $ls_gridname; ?>').datagrid('reload');
								});
			                }
			            });
                    } 

				}
			}],<?php 
			} // -->> Toolbar [End]
			?>
			onClickRow:function(rowIndex){
				var lastIndex = $('#<?php echo $ls_gridname; ?>').data('selectedIndex');
				$('#<?php echo $ls_gridname; ?>').data('selectedIndex', rowIndex);
			},
			onLoadSuccess:function(){ }
		});


	});
	
</script>
<table id="<?php echo $ls_gridname; ?>" style="width:600;height:auto" singleSelect="true" idField="index_no" showFooter="true">
<thead>
    <tr>
    	<th field="id_detail_penghargaan_pk" hidden="true"></th>
        <th field="no_sk_penghargaan" width="150" >No SK Penghargaan</th>
        <th field="nama_penghargaan" width="200" >Penghargaan</th>
        <th field="tgl_penghargaan" width="100" >Tgl Penghargaan</th>
        <th field="pemberi_penghargaan" width="150" >Pemberi Penghargaan</th>
        <th field="ket_penghargaan" width="200" >Keterangan</th>
    </tr>
</thead>
</table>
